package com.example.demoweb.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 赵恒
 * @date 2023/8/16
 */
@Slf4j
public class RequestInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String uri = request.getRequestURI();
        // 按照 /api 分隔
        log.info("uri:{}", uri);
        String userId = request.getParameter("userId");
        if (StringUtils.isEmpty(userId)) {
            log.error("userId为空");
            throw new RuntimeException("userId为空");
        }


        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
